<template>
  <BasicTable @register="registerTable">
    <template #action="{ record }">
      <TableAction
        :actions="[
          {
            icon: 'clarity:note-edit-line',
            tooltip: '确定',
            onClick: handleEdit.bind(null, record),
          },
        ]"
      />
    </template>
    <template #footer>
      <div class="text-center pt-2 pb-2"> 注：如果以#开头，则表示从资源文件中获取 </div>
    </template>
  </BasicTable>
</template>
<script lang="ts">
  import { defineComponent, ref } from 'vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { columns, dataSource } from './flowBtnConfiguration.data';
  import {
    getConfigEditFlowButtonPage,
    getConfigUpdateFlowButton,
  } from '/@/api/flowManage/flowManage';
  import { useMessage } from '/@/hooks/web/useMessage';
  export default defineComponent({
    name: 'FlowBtnConfiguration',
    components: { BasicTable, TableAction },
    setup() {
      const { createMessage } = useMessage();
      const [registerTable, { reload, updateTableDataRecord, setProps }] = useTable({
        title: '',
        api: getConfigEditFlowButtonPage,
        rowKey: 'id',
        columns,
        dataSource,
        formConfig: {
          labelWidth: 120,
          schemas: [],
          autoSubmitOnEnter: true,
        },
        useSearchForm: false,
        showTableSetting: false,
        bordered: true,
        showIndexColumn: false,
        canResize: false,
        pagination: false,
        // showHeader: false,
        afterFetch: (data) => {
          return data.map((item) => {
            return {
              ...item,
              newValue: item.value,
            };
          });
        },
        scroll: { y: window?.innerHeight - 260 },
        actionColumn: {
          width: 60,
          title: '操作',
          dataIndex: 'action',
          slots: { customRender: 'action' },
        },
      });

      const handleEdit = async (record) => {
        try {
          handleSetProps(true);
          await getConfigUpdateFlowButton(record);
          createMessage.success('操作成功');
          reload();
        } finally {
          handleSetProps(false);
        }
      };
      const handleSetProps = (bool) => {
        setProps({ loading: bool });
      };

      return {
        registerTable,
        handleEdit,
      };
    },
  });
</script>
